<div class="layui-collapse" lay-accordion>
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">网站</h2>
        <div class="layui-colla-content">
            <form class="layui-form">
                <table class="layui-table layui-table-content" lay-skin="nob">
                    <tbody>
                    <tr>
                        <th width="150"><span class="red">*</span>状态</th>
                        <td>
                            <input type="checkbox" name="disable" lay-verify="" value="1"
                                   data-val="${websiteConfig.disable?string('true','false')}"
                                   lay-skin="switch" lay-text="开启|关闭">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>名称</th>
                        <td>
                            <input type="text" name="name" placeholder="请输入网站名称" lay-verify="required"
                                   autocomplete="off" value="${websiteConfig.name!}" class="layui-input">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>域名</th>
                        <td>
                            <input type="text" name="domain" placeholder="请输入网站域名" lay-verify="required"
                                   autocomplete="off" value="${websiteConfig.domain!}" class="layui-input">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>Logo</th>
                        <td>
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="btn_webSiteLogo_upload">上传图片</button>
                                <div class="layui-upload-list">
                                    <img id="img_webSiteLogo_upload" class="layui-upload-img"
                                         src="${websiteConfig.logo!'/resources/images/administrate/upload_default.png'}"
                                         style="width: 92px; height: 92px; margin: 0 10px 10px 0;">
                                    <p id="text_webSiteLogo_upload"></p>
                                    <input type="hidden" name="logo" value="${websiteConfig.logo!}">
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>图标</th>
                        <td>
                            <div class="layui-upload">
                                <button type="button" class="layui-btn" id="btn_webSiteIco_upload">上传图片</button>
                                <div class="layui-upload-list">
                                    <img id="img_webSiteIco_upload" class="layui-upload-img"
                                         src="${websiteConfig.ico!'/resources/images/administrate/upload_default.png'}"
                                         style="width: 92px; height: 92px; margin: 0 10px 10px 0;">
                                    <p id="text_webSiteIco_upload"></p>
                                    <input type="hidden" name="ico" value="${websiteConfig.ico!}">
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>标题</th>
                        <td>
                            <input type="text" name="title" placeholder="请输入网站标题" lay-verify="required"
                                   autocomplete="off" value="${websiteConfig.title!}" class="layui-input">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>关键词</th>
                        <td>
                            <input type="text" name="keywords" placeholder="请输入网站关键词" lay-verify="required"
                                   autocomplete="off" value="${websiteConfig.keywords!}" class="layui-input">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>描述</th>
                        <td>
                            <textarea name="description" lay-verify="" placeholder="请输入网站描述"
                                      class="layui-textarea">${websiteConfig.description!}</textarea>
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>备案信息</th>
                        <td>
                            <input type="text" name="filing" placeholder="请输入网站备案信息" lay-verify="required"
                                   autocomplete="off" value="${websiteConfig.filing!}" class="layui-input">
                        </td>
                    </tr>
                    <tr>
                        <th width="150"><span class="red">*</span>统计代码</th>
                        <td>
                            <textarea name="statisticsCode" lay-verify="" placeholder="请输入统计代码"
                                      class="layui-textarea">${websiteConfig.statisticsCode!}</textarea>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="layui-button">
                    <button class="layui-btn" style=" min-width: 150px;" lay-submit lay-filter="formSubmitWebSite">提 交
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<#macro script>
    <script>
        layui.use(['jquery', 'form', 'layer', 'element', 'upload'], function () {
            var $ = layui.jquery,
                form = layui.form,
                element = layui.element,
                upload = layui.upload;

            /*网站Logo上传*/
            var upload_webSiteLogo = upload.render({
                elem: '#btn_webSiteLogo_upload'
                , url: '/ueditor?action=uploadimage'
                , field: 'upfile'
                , accept: 'images'
                , exts: 'jpg|png|gif|bmp|jpeg'
                , size: 1024
                , before: function () {
                    layer.load(2);
                }
                , done: function (res) {
                    layer.closeAll('loading');
                    if (res.state == "SUCCESS") {
                        layer.msg('上传成功');
                        $("input[name='logo']").val(res.url);
                        $("#img_webSiteLogo_upload").attr("src", res.url);
                    }
                    else {
                        $("#img_webSiteLogo_upload").attr("src", "/resources/images/administrate/upload_error.png");
                        layer.msg(res.state);
                    }
                }
                , error: function () {
                    layer.closeAll('loading');
                    $("#img_webSiteLogo_upload").attr("src", "/resources/images/administrate/upload_error.png");
                    var text = $('#text_webSiteLogo_upload');
                    text.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload" style="color:#ffffff;">重试</a>');
                    text.find('.demo-reload').on('click', function () {
                        upload_webSiteLogo.upload();
                    });
                }
            });

            /*网站图标上传*/
            var upload_webSiteIco = upload.render({
                elem: '#btn_webSiteIco_upload'
                , url: '/ueditor?action=uploadimage'
                , field: 'upfile'
                , accept: 'images'
                , exts: 'ico'
                , size: 1024
                , before: function () {
                    layer.load(2);
                }
                , done: function (res) {
                    layer.closeAll('loading');
                    if (res.state == "SUCCESS") {
                        layer.msg('上传成功');
                        $("input[name='ico']").val(res.url);
                        $("#img_webSiteIco_upload").attr("src", res.url);
                    }
                    else {
                        $("#img_webSiteIco_upload").attr("src", "/resources/images/administrate/upload_error.png");
                        layer.msg(res.state);
                    }
                }
                , error: function () {
                    layer.closeAll('loading');
                    $("#img_webSiteIco_upload").attr("src", "/resources/images/administrate/upload_error.png");
                    var text = $('#text_webSiteIco_upload');
                    text.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload" style="color:#ffffff;">重试</a>');
                    text.find('.demo-reload').on('click', function () {
                        upload_webSiteIco.upload();
                    });
                }
            });

            $(function () {
                if ($("input[name='disable']").data("val")) {
                    $("input[name='disable']").attr("checked", true);
                }
                else {
                    $("input[name='disable']").attr("checked", false);
                }
                form.render('checkbox');
            });


            /*提交*/
            form.on('submit(formSubmitWebSite)', function (data) {
                if (data.field.disable == null) {
                    data.field.disable = false;
                }
                else {
                    data.field.disable = true;
                }
                if (data.field.logo == "") {
                    delete data.field.logo;
                }
                if (data.field.ico == "") {
                    delete data.field.ico;
                }
                $.ajax({
                    type: "POST",
                    url: "/administrate/setting/website/save",
                    data: data.field,
                    async: false,
                    dataType: "json",
                    success: function (result) {
                        layer.msg(result.msg);
                    }
                });
                return false;
            });


        });
    </script>
</#macro>